package com.ruoyi.system.controller;

import com.ruoyi.system.DTO.Reques.vms.SkuClassDTO;
import com.ruoyi.system.DTO.Reques.vms.SkuClassUpdateDto;
import com.ruoyi.system.pojo.vms.SkuClassEntity;
import com.ruoyi.system.service.SkuClassService;
import com.ruoyi.system.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Description:
 *
 * @author JourWon
 * @date Created on 2025/5/14
 */
@RestController
@RequestMapping("/vm-service")
public class SkuClassController {

    @Autowired
    private SkuClassService skuClassService;

    @PostMapping("/skuClass")
    public ResponseEntity<Boolean> create(@RequestBody @Valid SkuClassDTO skuClassDTO) {
        return ResponseEntity.ok(skuClassService.create(skuClassDTO));
    }

    /**
     * 查询商品类型列表
     * @param pageIndex
     * @param pageSize
     * @param className
     * @return
     */
    @GetMapping("/skuClass/search")
    public PageResult<SkuClassEntity> search(
            @RequestParam(required = false) Integer pageIndex,
            @RequestParam(required = false) Integer pageSize,
            @RequestParam(required = false) String className) {

        return skuClassService.search(pageIndex, pageSize, className);
    }

    @PutMapping("/skuClass/{classId}")
    public boolean updateSkuClass(@PathVariable Integer classId,
                                  @RequestBody SkuClassUpdateDto updateDto) {
        return skuClassService.updateSkuClass(classId, updateDto);
    }

    @DeleteMapping("/skuClass/{classId}")
    public boolean deleteSkuClass(@PathVariable Integer classId) {
        return skuClassService.deleteSkuClass(classId);
    }
}
